<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> </title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctx!}/assets/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx!}/assets/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctx!}/assets/css/animate.css" rel="stylesheet">
    <link href="${ctx!}/assets/css/style.css?v=4.1.0" rel="stylesheet">

</head>


<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>订单提交</h5>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="frm" method="post" action="${ctx!}/admin/role/edit">
                        	<input type="hidden" id="id" name="id" value="${purchase.id}">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">设备：</label>
                                <div class="col-sm-8">
                                    <select name="deviceId" id="productVersion" style="width:178px;"  value="">
                                        <option value="">--请选择--</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">采购数量：</label>
                                <div class="col-sm-8">
                                    <input id="purchaseNum" name="purchaseNum" class="form-control" type="text" value="${purchase.purchaseNum}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">单价：</label>
                                <div class="col-sm-8">
                                    <input id="usualPrice" name="usualPrice" class="form-control" type="text" value="${purchase.usualPrice}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">采购时间：</label>
                                <div class="col-sm-8">
                                    <input id="planTime" name="planTime" readonly="readonly" class="laydate-icon form-control layer-date" value="${purchase.planTime}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">采购人：</label>
                                <div class="col-sm-8">
                                    <input id="operatorName" name="operatorName" class="form-control" value="${purchase.operatorName}">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" type="submit">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>


    <!-- 全局js -->
    <script src="${ctx!}/assets/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctx!}/assets/js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js -->
    <script src="${ctx!}/assets/js/content.js?v=1.0.0"></script>

    <!--  plugin javascript-->
    <script src="${ctx!}/assets/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${ctx!}/assets/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${ctx!}/assets/js/plugins/layer/layer.min.js"></script>
    <script src="${ctx!}/assets/js/plugins/layer/laydate/laydate.js"></script>

    <script>

        $(document).ready(function () {
            //外部js调用
            laydate({
                elem: '#planTime', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus' //响应事件。如果没有传入event，则按照默认的click
            });

            $("#frm").validate({
                rules: {
                    deviceId: {
                        required: true
                    },
                    purchaseNum: {
                        required: true
                    },
                    usualPrice: {
                        required: false
                    },
                    planTime: {
                        date:true,
                        required: true
                    },
                    operatorName:{
                        required:false
                    }
                },
                messages: {},
                submitHandler:function(form){
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "${ctx!}/business/purchase/edit",
                        data: $(form).serialize(),
                        success: function(msg){
                            layer.msg(msg.message, {time: 2000},function(){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index);
                            });
                        }
                    });
                }
            });
        });


        $(function(){
            initDevices();
        });

        function initDevices() {
            $.ajax({
                type: "POST",//请求方式
                url: "${ctx!}/business/device/all",
                dataType: "json",//数据类型可以为 text xml json  script  jsonp
                success: function (result) {//返回的参数就是 action里面所有的有get和set方法的参数
                    $.each(result, function (index, obj) {
                        $("#productVersion").append("<option value=" + obj['id'] + " >" + obj['deviceName'] + "</option>");
                    })
                }
            });
        }

    </script>

</body>

</html>
